import * as yaml from 'js-yaml';
import { Renderer } from './engine';
import { Behaviour } from './engine/Behaviour';
import { Rectangle } from './engine/math';
import { boolean } from './engine/validators/boolean';
import { number } from './engine/validators/number';
import { string } from './engine/validators/string';

export class AnimationRenderer extends Behaviour implements Renderer {
    @string()
    source = "";

    @string()
    config = ""

    @string()
    action = ''

    @boolean()
    IsCircle = true;

    allTime:number = 0;//动画播放的总时间

    advancedTime: number = 0;

    currentFrame: number = 0;

    _configData: any;
    getConfig() {
        if (!this._configData) {
            const text = this.engine.resourceManager.getText(this.config)
            this._configData = yaml.load(text)
        }
        return this._configData;
    }

    sourceRect = { x: 0, y: 157, width: 100, height: 157 }

    getBounds(): Rectangle {
        const img = this.engine.resourceManager.getImage(this.source)
        return {
            x: 0,
            y: 0,
            width: 100,
            height: 157,
        };
    }
}